package v1

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"server/internal/model"
	"server/pkg/app"
	"strconv"
)

func CreatePerformance(c *gin.Context) {
	performance := &model.Performance{}
	ShouldBind(performance, c)
	err := performance.Create()
	if err != nil {
		c.String(http.StatusOK, err.Error())
		return
	}
	c.String(http.StatusOK, "创建performance性能任务成功")
}

func ListPerformance(c *gin.Context) {
	performance := &model.Performance{}
	pages := &app.Page{}
	pages.Info(c)
	fio_list, total := performance.List(pages)
	c.JSON(http.StatusOK, gin.H{
		"total": total,
		"data":  fio_list,
	})
}

func UpdatePerformance(c *gin.Context) {
	performance := &model.Performance{}
	ShouldBind(performance, c)
	err := performance.Update()
	if err != nil {
		c.String(http.StatusOK, err.Error())
		return
	}
	c.String(http.StatusOK, "更新performance性能任务成功")
}

func DeletePerformance(c *gin.Context) {
	performance := &model.Performance{}
	id := c.Param("id")
	performance.ID, _ = strconv.Atoi(id)
	err := performance.Delete()
	if err != nil {
		c.String(http.StatusOK, err.Error())
		return
	}
	c.String(http.StatusOK, "删除性能任务成功")
}
